﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using weikebuluo.DAL;
using weikebuluo.Common;
using weikebuluo.Model;


namespace weikeweixin.web.admin.cs  
{
    public class rootbase : System.Web.UI.Page

    {

        a_user_dal userdal = new a_user_dal();
        w_wechat_dal wecahtdal = new w_wechat_dal();

        public string user_id = "";
        public string user_name = "";
        public string wechat_id = "";
        public string wechat_name = "";
        public int user_level = 0;

        protected override void OnInit(EventArgs e)
        {
            //Session["user_id"] = "1";
            // Session["user_name"] = "hi_again"; 
            //Session["user_name"] = "weijing1";
            //Session["user_name"] = "weike2014";
            //Session["user_level"] = "1000";

            if (Session["user_name"] == null)
            {
                Response.Write("<script Language=\"Javascript\">top.location=\"/web/pcweb/index.aspx\";");
                Response.Write("</script>");
                Response.End();

            }
            else if (Session["user_level"] != null)
            {
                if (int.Parse(Session["user_level"].ToString()) != 1000)
                {
                    Response.Write("<script Language=\"Javascript\">top.location=\"/web/pcweb/index.aspx\";");
                    Response.Write("</script>");
                    Response.End();
                }
                else
                {
                    getuser();
                }
            }

            else
            {
                getuser();
                //if (!getapi())
                //{


                //    if (Request.QueryString["bindapi"] == "1")
                //    {
                //        Response.Write("<script Language=\"Javascript\">alert(\"请先配置微信接口：【我的微信】》【微信配置】\")");
                //        Response.Write("</script>");
                //        Response.Write("<script Language=\"Javascript\">location.href=\"/web/wechat/bindapi.aspx\";");
                //        Response.Write("</script>");
                //        Response.End();
                //    }
                //}
            }
        }

        #region 获取用户信息
        private void getuser()
        {
            DataTable dt = userdal.GetList("user_name='" + Session["user_name"] + "'").Tables[0];
            user_id = dt.Rows[0]["user_id"].ToString().Trim();
            user_name = dt.Rows[0]["user_name"].ToString().Trim();

            if (dt.Rows[0]["user_level"] != null)
            {
                user_level = int.Parse(dt.Rows[0]["user_level"].ToString().Trim());
            }

            Session["user_id"] = dt.Rows[0]["user_id"].ToString().Trim();
            Session["user_name"] = dt.Rows[0]["user_name"].ToString().Trim();
            Session["user_level"] = user_level;
        }
        #endregion

        #region 获取接口信息
        private bool getapi()
        {
            DataTable dtwecaht = wecahtdal.GetList("user_id =" + Session["user_id"]).Tables[0];
            if (dtwecaht.Rows.Count > 0)
            {
                wechat_id = dtwecaht.Rows[0]["wechat_id"].ToString();
                wechat_name = dtwecaht.Rows[0]["wechat_name"].ToString();
                return true;
            }
            else
            {
                return false;
            }

        }
        #endregion

    }
}